package demo4031.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import demo4031.dso.mapper.AppxMapper;
import demo4031.dso.service.AppServicePlus;
import demo4031.model.AppxModel;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.snack.core.utils.StringUtil;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

import java.util.Objects;

/**
 * 分面演示（使用sqlhelper组件）
 *
 * */
@Mapping("/page/")
@Controller
public class PageController {
    @Db
    private AppxMapper appxMapper;

    @Inject
    private AppServicePlus appServicePlus;

    @Mapping("test")
    public Object test(String key) throws Throwable {
        Page<AppxModel> page = new Page<>(1, 2);
        return appxMapper.appx_get_page(page);
    }

    @Mapping("test1")
    public Object test1(String key) throws Throwable {
        Page<AppxModel> page = new Page<>(1, 3);

        LambdaQueryWrapper<AppxModel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StringUtil.isEmpty(key), AppxModel::getAppKey, key);
        return appServicePlus.page(page, queryWrapper);
    }
}
